<?php
    defined('_JEXEC') or die(); 
    JHTML::_('behavior.tooltip'); 
    $listOrder    = @$this->lists['order'];
    $listDirn    = @$this->lists['order_Dir'];
?>
<style>
    #tbl_filter{
        margin: 0 ; padding: 0 ;
    }
    #tbl_filter td{
        padding: 3px;
    }
    #tbl_filter input, #tbl_filter img {
        float: left;
        margin: 0 5px 0 0;
        width: auto;
    }
    .outlet-list, .outlet-list-extra { display: none; }
    .date-from-to { border-bottom: 1px solid #CCC; padding-bottom: 3px; font-size: 1.4em; width: 350px; }
    .date-from-to span { color: #e72222; }
    .breadscrumb-report { padding: 10px 0 10px 20px; background: url(/images/steps.png) 10px top no-repeat; height: 16px; line-height: 16px; width: 700px; }
    .breadscrumb-report a, .breadscrumb-report span { width: 204px; display: block; float: left; font-size: 1.5em; color: #FFF; text-align: center; }    
    .breadscrumb-report .step2 { width: 265px; }
    .breadscrumb-report .step3 { width: 214px; }
    table.adminlist tbody tr td { padding: 8px 8px; }
    table.adminlist thead th { padding: 8px; }
</style>
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root(); ?>js/multiselect/jquery.multiselect.css" />
<link rel="stylesheet" type="text/css" href="<?php echo JURI::root(); ?>js/multiselect/jquery-ui.css" />
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/jquery.js"></script>
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?php echo JURI::root(); ?>js/multiselect/jquery.multiselect.js"></script>

<script type="text/javascript">
    function submitform(pressbutton){
        var form = document.adminForm ;
        //alert(pressbutton)
        if (pressbutton)
        {
            form.task.value=pressbutton ;
        }
        if ((pressbutton=='send_redemp_notice_email')||(pressbutton=='send_redemp_pick_up_notice')){
              form.controller.value="reports" ;
        }
        form.submit();
    }
    jQuery(function(){
        jQuery("#filter_field").multiselect({
            selectedList: 0,
            noneSelectedText: 'Select Fields',
            selectedText: "# of # selected"
        }); 
        jQuery("#pick_up_at").multiselect({
            selectedList: 0,
            noneSelectedText: 'Select outlet',
            selectedText: "# of # selected"
        }); 
        if(jQuery("#extra_sort_by").val() == "outlet"){
            jQuery(".outlet-list").show();
            jQuery(".outlet-list-extra").hide();
        }
        
        jQuery("#extra_sort_by").change(function(){
            if(jQuery(this).val() == "outlet")
            {
                jQuery(".outlet-list").show();
                jQuery(".outlet-list-extra").hide();
            }
            else
            {
                jQuery(".outlet-list").hide();
                jQuery(".outlet-list-extra").show();
            }
        });
        jQuery("#element-box").before("<div class='breadscrumb-report'><a href='index.php?option=com_wrd&controller=reports' class='step1'>Reports</a><span class='step2'>Member Spending Report</span><span class='step3'>Detail</span></div>");
    });
</script>
<div class="col width-100">    
    
        <div id="editcell">
            <form action="<?php echo JRoute::_("index.php?option=com_wrd")?>" method="post" name="filterform" >
                <table style='margin-bottom:5px' id="tbl_filter">
                    <tbody>
                        <tr>
                            <td align="left" valign="bottom" style="border-right: 1px solid #d0d0d0;">
                                <table >
                                    <tr valign="top">
                                        <td valign="top" width='35px'>From</td>        
                                        <td valign="top" width='150px'>
                                            <?php
                                                echo JHTML::_ ( 'calendar', ($this->pr['date_from'] != '') ? $this->pr['date_from'] : '', 'date_from', 'date_from', '%Y-%m-%d');
                                            ?>
                                        </td>
                                       
                                    </tr>
                                    <tr>
                                        <td width='35px'>To</td>        
                                        <td width='150px'>
                                            <?php
                                                echo JHTML::_ ( 'calendar', ($this->pr['date_to'] != '') ? $this->pr['date_to'] : '', 'date_to', 'date_to', '%Y-%m-%d');
                                            ?>
                                        </td>
                                      
                                    </tr>
                                </table>
                            </td>
                            <td align="left" valign="middle" style="border-right: 1px solid #d0d0d0;">
                                <table >
                                    <tr>
                                        <td>Sort by: </td>
                                        <td style="width: 230px;">
                                            <?php echo $this->lists['extra_sort_by'] ; ?>                                            
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <div class="outlet-list">Outlet</div>
                                        </td>
                                        <td style="text-align: left ;">
                                            <div class="outlet-list"><?php echo $this->lists['filter_pick_up_outlet'] ; ?></div><div class="outlet-list-extra">&nbsp;</div>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td align="left" valign="bottom" style="border-right: 1px solid #d0d0d0;">
                                <table >
                                    <tr>
                                        <td>
                                             Display fields: 
                                        </td>
                                        <td style="width: 236px;">
                                            <?php echo $this->lists['filter_field'] ; ?>                                            
                                        </td>
                                    </tr>
                                    <tr>
                                        
                                        <td>
                                            &nbsp;
                                        </td>
                                        <td style="text-align: left ;">
                                            <input type="submit" name="view" onclick="document.getElementById('submitViewExcel').value = 'submitViewExcel';  document.getElementById('task').value = 'memberpendingreportdetail';" value="View" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td align="left" valign="bottom">
                                <table >
                                    <tr>
                                        <td>
                                             Top: 
                                        </td>
                                        <td>
                                            Choose: 
                                            <select name="topDisplaySelect" id="topDisplaySelect">
                                                <option value="10">10</option>
                                                <option value="20">20</option>
                                                <option value="50">50</option>
                                                <option value="100">100</option>
                                                <option value="">All</option>
                                            </select>&nbsp;or type&nbsp;
                                            <input name="topDisplaytbx" id="topDisplaytbx" type="text" style="width: 60px; float: none;" />
                                        </td>
                                    </tr>
                                    <tr>
                                        
                                        <td>
                                            &nbsp;
                                        </td>
                                        <td style="text-align: left ;padding: 10px 0 0;">                                            
                                            <input type="submit" id="exportexcel" name="exportexcel" onclick="document.getElementById('task').value = 'exmemberspendingreportdetail'" value="Export excel" />
                                        </td>
                                    </tr>
                                </table>
                            </td>                            
                        </tr>
                    </tbody>
                </table>
                <input type="hidden" name="controller" value="reports" />
                <input type="hidden" name="option" value="com_wrd" />
                <input type="hidden" name="submitViewExcel" id="submitViewExcel" value="" />
                <input type="hidden" name="task" id="task" value="" />
            </form>    
            <br />
            <h3 class="date-from-to"><?php echo $this->lists['date']; ?></h3>
            <form  id="adminForm"  action="<?php echo JRoute::_("index.php?option=com_wrd")?>" method="post" name="adminForm" >
                <table width="100%" class="adminlist">
                    <thead>
                        <tr>                             
                            <th nowrap="nowrap">
                                 Outlet Name
                            </th>
                             
                            <?php if($this->filter_field['cover']): ?> 
                            <th nowrap="nowrap">
                                Cover
                             </th>        
                             <?php endif; ?>
                             
                             
                             <!-- 3 -->   
                             <?php if($this->filter_field['food']): ?>
                             <th nowrap="nowrap">
                                 Food
                             </th>
                             <?php endif; ?>
                             
                             <?php if($this->filter_field['beverage']): ?>
                             <th nowrap="nowrap">
                                 Beverage Alcoholic
                             </th>
                             <?php endif; ?>
                                     
                             
                             <?php if($this->filter_field['other']): ?>
                             <th nowrap="nowrap">
                                 Misc./Ciger
                             </th>
                             <?php endif; ?>
                             
                             <?php if($this->filter_field['vat']): ?>
                             <th nowrap="nowrap">
                                 VAT
                             </th> 
                             <?php endif; ?>
                             
                             <?php if($this->filter_field['service']): ?>
                             <th nowrap="nowrap">
                                 Service Charge
                             </th> 
                             <?php endif; ?>
                             
                             <!-- 3 -->
                             <th nowrap="nowrap">
                                 Total
                             </th>
                             
                             <?php if($this->filter_field['totalvisit']): ?>
                             <th nowrap="nowrap">
                                 Total Visit
                             </th>   
                             <?php endif; ?>
                             
                             <?php if($this->filter_field['averagespending']): ?>
                             <th nowrap="nowrap">
                                 Average Spending per cover
                             </th>   
                             <?php endif; ?>
                             
                             
                             <?php if($this->filter_field['foodratio']): ?>
                             <th nowrap="nowrap">
                                 Food ratio
                             </th>                                                       
                             <?php endif; ?>
                             
                             <?php if($this->filter_field['bvratio']): ?>
                             <th nowrap="nowrap">
                                 BV Ratio
                             </th>   
                             <?php endif; ?>
                             
                             <?php if($this->filter_field['miscratio']): ?>
                             <th nowrap="nowrap">
                                 Misc Ratio
                             </th>                                                       
                             <?php endif; ?>
                                                      
                        </tr>
                    </thead>
                    <tbody>
                         <?php
                               $k = 0;
                               if(count($this->items) > 0): 
                                for ($i=0, $n= count( $this->items ); $i < $n; $i++):
                                    $row = &$this->items[$i];
                                    //$checked     = JHTML::_('grid.checkedout',   $row, $i);
                            ?>    
                                 <tr class="<?php echo "row$k"; ?>" >                                   
                                    <td>
                                          <?php echo $row->outlet; ?>
                                    </td>
                                                                       
                                    <!-- 3 -->
                                    <?php if($this->filter_field['cover']): ?>
                                     <td nowrap="nowrap" align="center">  
                                         <?php echo $row->cover; ?>
                                     </td>
                                     <?php endif; ?>
                                     
                                     
                                     <?php if($this->filter_field['food']): ?>
                                     <td nowrap="nowrap" align="right">  
                                         <?php echo number_format($row->food, 0, ',', ','); ?>
                                     </td>
                                     <?php endif; ?>
                                     
                                     
                                    <?php if($this->filter_field['beverage']): ?>                                
                                    <td nowrap="nowrap" align="right">  
                                        <?php echo number_format($row->beverage, 0, ',', ','); ?>
                                    </td>
                                    <?php endif; ?>
                                    
                                    
                                    <?php if($this->filter_field['other']): ?>
                                    <td nowrap="nowrap" align="right">  
                                        <?php echo number_format($row->other, 0, ',', ','); ?>
                                    </td>
                                    <?php endif; ?>
                                    
                                    <!-- 3 -->
                                    <?php if($this->filter_field['vat']): ?>
                                    <td nowrap="nowrap" align="right">  
                                        <?php echo number_format((int)$row->vat, 0, ',', ','); ?>
                                    </td>
                                    <?php endif; ?>
                                    
                                    
                                    <?php if($this->filter_field['service']): ?>
                                    <td nowrap="nowrap" align="right">  
                                        <?php echo number_format((int)$row->sc, 0, ',', ','); ?>
                                    </td>
                                    <?php endif; ?>
                                    
                                    
                                    <?php 
                                        $total = (int)$row->food + (int)$row->beverage + (int)$row->other;
                                    ?>
                                    <td nowrap="nowrap" align="right">  
                                        <?php echo number_format(($total + (int)$row->vat + (int)$row->sc), 0, ',', ','); ?>
                                    </td>
                                    
                                    
                                    <?php if($this->filter_field['totalvisit']): ?>
                                    <td nowrap="nowrap" align="right">  
                                        <?php echo $row->total_visit; ?>
                                    </td>          
                                    <?php endif; ?>
                                    
                                    
                                    <?php if($this->filter_field['averagespending']): ?>
                                    <td nowrap="nowrap" align="right">  
                                        <?php if($row->cover){ echo number_format((float)$total/$row->cover, 0, '.', ','); }?>
                                    </td>          
                                    <?php endif; ?>
                                    
                                    
                                    <!-- 3 -->                                                                     
                                    <?php if($this->filter_field['foodratio']): ?>
                                    <td nowrap="nowrap" align="center">  
                                        <?php if($total){ echo round ($row->food*100/$total); }?>%
                                    </td>
                                    <?php endif; ?>
                                                                                                         
                                    
                                    <?php if($this->filter_field['bvratio']): ?>
                                    <td nowrap="nowrap" align="center">  
                                        <?php if($total){ echo round ($row->beverage*100/$total); }?>%
                                    </td>
                                    <?php endif; ?>
                                    
                                    
                                    <?php if($this->filter_field['miscratio']): ?>
                                    <td nowrap="nowrap" align="center">  
                                        <?php if($total){ echo (100-(round ($row->food*100/$total) + round ($row->beverage*100/$total))); }?>%
                                    </td>
                                    <?php endif; ?>                                                                        
                                 </tr>
                             <?php 
                                 $k = 1 - $k ;     
                                 endfor; 
                                 endif; 
                             ?>
                         </tbody>
                     <tfoot>
                        <tr>
                            <td colspan="16">
                                <?php
                                     echo $this->pagination->getListFooter();
                                ?>
                            </td>
                        </tr>
                    </tfoot>
                </table>
                <input type="hidden" name="controller" value="reports" />
                <input type="hidden" name="option" value="com_wrd" />
                <input type="hidden" name="task" value="memberpendingreportsum" />
                <input type="hidden" name="boxchecked" value="0" />
                <?php echo JHTML::_( 'form.token' ); ?>
            </form>
        </div>
        
</div>
<?php 
    //$this->downloadFileExcel();
?>